<template>
  <el-card>
    <!--条件查询开始-->
    <el-form ref="queryParams" :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="所属部门" prop="deptId">
        <el-select
            v-model="queryParams.deptId"
            placeholder="请选择部门"
            clearable
            size="small"
            style="width:240px">
          <el-option
              v-for="dict in deptOptions"
              :key="dict.deptId"
              :label="dict.deptName"
              :value="dict.deptId"/>
        </el-select>
      </el-form-item>
      <el-form-item label="用户姓名" prop="userName">
        <el-input
            v-model="queryParams.username"
            placeholder="请输入用户姓名"
            clearable
            size="small"
            style="width:240px"/>
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
            v-model="queryParams.phone"
            placeholder="请输入手机号"
            clearable
            size="small"
            style="width:240px"/>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
            v-model="queryParams.status"
            placeholder="可用状态"
            clearable size="small"
            style="width:240px">
          <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"/>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
            v-model="queryParams.dateRange"
            size="small"
            style="width:240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholde="开始日期"
            end-placeholde="结束日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--条件查询结束-->
    <!-- 表格工具按钮开始 -->
    <el-row :gutter="10" style="margin-bottom: 8px;">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="batchDelete()">
          批量删除
        </el-button>
      </el-col>
      <!-- <el-col :span="1.5">
          <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleResetPwd">
              重置密码
          </el-button>
      </el-col> -->
    </el-row>
    <!-- 表格工具按钮结束 -->
    <!-- 数据表格开始 -->
    <el-table border :data="userTableList" @selection-change="selectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="邮箱：">
              <span>{{ props.row.email }}</span>
            </el-form-item>
            <el-form-item label="擅长：">
              <span>{{ props.row.strong }}</span>
            </el-form-item>
            <el-form-item label="荣耀：">
              <span>{{ props.row.honor }}</span>
            </el-form-item>
            <el-form-item label="简介：">
              <span>{{ props.row.introduction }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="用户ID" align="center" prop="userId"/>
      <el-table-column label="用户姓名" align="center" prop="userName"/>
      <el-table-column label="部门" align="center" prop="deptId" :formatter="deptFormatter"/>
      <el-table-column label="手机号码【登陆身份】" width="180" align="center" prop="phone"/>
      <el-table-column label="性别" align="center" prop="sex" :formatter="sexFormatter"/>
      <el-table-column label="年龄" align="center" prop="age"/>
      <el-table-column label="是否排班" align="center" prop="schedulingFlag" :formatter="schedulingFlagFormatter"/>
      <el-table-column label="级别" prop="userRank" align="center" :formatter="userRankFormatter"/>
      <el-table-column label="背景" prop="background" align="center" :formatter="backgroundFormatter"/>
      <el-table-column label="状态" prop="status" align="center" :formatter="statusFormatter" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="200"/>
      <el-table-column label="操作" align="center" width="250">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-edit" size="mini" @click="handleUpdate(scope.row)">修改
          </el-button>
          <el-button v-if="scope.row.userId!=1" type="text" icon="el-icon-delete" :disabled="single" size="mini"
                     @click="handleDelete(scope.row)">删除
          </el-button>
          <el-button v-if="scope.row.userId!=1" type="text" icon="el-icon-thumb" size="mini"
                     @click="handleSelectRole(scope.row)">分配角色
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 数据表格结束 -->
    <!-- 添加弹出层开始 -->
    <el-dialog
        :title="title"
        :visible.sync="addopen"
        width="800px"
        center
        append-to-body
    >
      <el-form ref="addform" :model="addform" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="userName">
              <el-input v-model="addform.userName" style="width:240px" placeholder="请输入用户名称"
                        clearable size="small"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号" prop="phone">
              <el-input v-model="addform.phone" style="width:240px"
                        placeholder="请输入手机号，作为登陆凭证"
                        clearable size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属科室" prop="deptId">
              <el-select
                  v-model="addform.deptId"
                  placeholder="所属科室"
                  clearable size="small"
                  style="width:240px"
              >
                <el-option
                    v-for="d in deptOptions"
                    :key="d.deptId"
                    :label="d.deptName"
                    :value="d.deptId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="级别" prop="userRank">
              <el-select
                  v-model="addform.userRank"
                  placeholder="用户级别"
                  clearable
                  size="small"
                  style="width:240px"
              >
                <el-option
                    v-for="d in userRankOptions"
                    :key="d.dictValue"
                    :label="d.dictLabel"
                    :value="d.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="年龄" prop="age">
              <el-input-number v-model="addform.age" clearable size="small"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="背景" prop="background">
              <el-select
                  v-model="addform.background"
                  placeholder="学历"
                  clearable
                  size="small"
                  style="width:240px"
              >
                <el-option
                    v-for="d in backgroundOptions"
                    :key="d.dictValue"
                    :label="d.dictLabel"
                    :value="d.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-radio-group v-model="addform.sex">
                <el-radio
                    v-for="d in sexOptions"
                    :key="d.dictValue"
                    :label="d.dictValue"
                    :value="d.dictValue"
                >{{ d.dictLabel }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="addform.status">
                <el-radio
                    v-for="dict in statusOptions"
                    :key="dict.dictValue"
                    :label="dict.dictValue"
                    :value="dict.dictValue"
                >{{ dict.dictLabel }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否参与排班" prop="schedulingFlag">
              <el-radio-group v-model="addform.schedulingFlag">
                <el-radio
                    v-for="d in schedulingOptions"
                    :key="d.dictValue"
                    :label="d.dictValue"
                    :value="d.dictValue"
                >{{ d.dictLabel }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="addform.email" style="width:240px" placeholder="请输入用户邮箱" clearable
                        size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="擅长" prop="strong">
              <el-input v-model="addform.strong" type="textarea" placeholder="请输入用户擅长"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="荣誉" prop="honor">
              <el-input v-model="addform.honor" type="textarea" placeholder="请输入用户相关荣誉"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="简介" prop="introduction">
              <el-input v-model="addform.introduction" type="textarea" placeholder="请输入用户简介"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addhandleSubmit()">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 添加弹出层结束 -->
    <!-- 修改弹出层开始 -->
    <el-dialog
        :title="title"
        :visible.sync="updateopen"
        width="800px"
        center
        append-to-body
    >
      <el-form ref="updateform" :model="updateform" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="userName">
              <el-input v-model="updateform.userName" style="width:240px" placeholder="请输入用户名称"
                        clearable
                        size="small"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号" prop="phone">
              <el-input v-model="updateform.phone" style="width:240px"
                        placeholder="请输入手机号，作为登陆凭证"
                        clearable size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属科室" prop="deptId">
              <el-select
                  v-model="updateform.deptId"
                  placeholder="所属科室"
                  clearable
                  size="small"
                  style="width:240px"
              >
                <el-option
                    v-for="d in deptOptions"
                    :key="d.deptId"
                    :label="d.deptName"
                    :value="d.deptId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="级别" prop="userRank">
              <el-select
                  v-model="updateform.userRank"
                  placeholder="用户级别"
                  clearable
                  size="small"
                  style="width:240px"
              >
                <el-option
                    v-for="d in userRankOptions"
                    :key="d.dictValue"
                    :label="d.dictLabel"
                    :value="d.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="年龄" prop="age">
              <el-input-number v-model="updateform.age" clearable size="small"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="背景" prop="background">
              <el-select
                  v-model="updateform.background"
                  placeholder="学历"
                  clearable
                  size="small"
                  style="width:240px"
              >
                <el-option
                    v-for="d in backgroundOptions"
                    :key="d.dictValue"
                    :label="d.dictLabel"
                    :value="d.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-radio-group v-model="updateform.sex">
                <el-radio
                    v-for="d in sexOptions"
                    :key="d.dictValue"
                    :label="d.dictValue"
                    :value="d.dictValue"
                >{{ d.dictLabel }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="updateform.status">
                <el-radio
                    v-for="dict in statusOptions"
                    :key="dict.dictValue"
                    :label="dict.dictValue"
                    :value="dict.dictValue"
                >{{ dict.dictLabel }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否参与排班" prop="schedulingFlag">
              <el-radio-group v-model="updateform.schedulingFlag">
                <el-radio
                    v-for="d in schedulingOptions"
                    :key="d.dictValue"
                    :label="d.dictValue"
                    :value="d.dictValue"
                >{{ d.dictLabel }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="updateform.email" style="width:240px" placeholder="请输入用户邮箱"
                        clearable
                        size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="擅长" prop="strong">
              <el-input v-model="updateform.strong" type="textarea" placeholder="请输入用户擅长"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="荣誉" prop="honor">
              <el-input v-model="updateform.honor" type="textarea" placeholder="请输入用户相关荣誉"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="简介" prop="introduction">
              <el-input v-model="updateform.introduction" type="textarea" placeholder="请输入用户简介"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updatehandleSubmit()">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 修改弹出层结束 -->

    <!-- 分页控件开始 -->
    <el-pagination
        :current="queryParams.pageNum"
        :page-sizes="[5, 10, 20, 30]"
        :pageSize="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="queryParams.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange" />
    <!-- 分页控件结束 -->
    <!-- 分配角色的弹出层开始 -->
    <el-dialog
        :title="title"
        :visible.sync="selectRoleOpen"
        width="900px"
        center
        append-to-body
    >
      <el-table
          ref="roleListTable"
          border
          :data="roleTableList"
          @selection-change="handleRoleTableSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="角色ID" align="center" prop="roleId" width="100"/>
        <el-table-column label="角色名称" align="center" prop="roleName"/>
        <el-table-column label="权限编码" align="center" prop="roleCode"/>
        <el-table-column label="备注" align="center" prop="remark"/>
        <el-table-column label="创建时间" align="center" prop="createTime"/>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSaveRoleUserSubmit" :disabled="roleIds.length===0">确 定</el-button>
        <el-button @click="cancelRoleUser">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 分配角色的弹出层结束 -->

  </el-card>
</template>
<script>
export default {
  data() {
    return {
      title: "用户管理",
      // 状态字典
      statusOptions: [],
      // 部门字典
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum:1,
        pageSize: 5,
      },
      // 增加表单数据
      addform: {},
      //背景的字典
      backgroundOptions:[],
      //性别字典
      sexOptions:[],
      //排班字典
      schedulingOptions:[],
      //级别字典
      userRankOptions:[],
      // 是否添加弹出层
      addopen: false,
      // 是否修改弹出层
      updateopen: false,
      //修改弹出层
      updateform: {},
      //表格数据
      userTableList:[],
      // 非多个禁用
      multiple: true,
      // 非单个禁用
      single: false,
      //被选择删除id
      userIds:[],
      // 选中的行
      selectedRows: [],
      // 分配角色不选时禁用
      roleSingle: {},
      // 批量删除不选时禁用
      userSingle: {},

      // 约束规则
      rules: {
        userName: [
          {required: true, message: '科室名称不能为空', trigger: 'blur'}
        ],
        deptId: [
          {required: true, message: '所属科室不能为空', trigger: 'blur'}
        ],
        userRank: [
          {required: true, message: '级别不能为空', trigger: 'blur'}
        ],
        // age: [
        //     {required: true, message: '年龄不能为空', trigger: 'blur'}
        // ],
        background: [
          {required: true, message: '学历不能为空', trigger: 'blur'}
        ],
        email: [
          {required: true, message: '邮箱不能为空', trigger: 'blur'}
        ],
        phone: [
          {required: true, message: '手机号不能为空', trigger: 'blur'},
          {pattern: /^1[3456789]\d{9}$/, message: '手机号码格式不正确', trigger: 'blur'},]
      },
      // 是否显示分配权限的弹出层
      selectRoleOpen: false,
      // roleIds 分配角色列表选择状态
      roleIds: [],
      // 角色数据
      roleTableList: [],
      // 当前选中的用户
      currentUserId: undefined

    }
  },
  //页面加载完毕执行
  created() {
    //加载所有的部门
    this.loadDept();
    //加载状态的内容
    this.loadStatus();
    //加载所有用户
    this.loadUser();
    //加载所有的背景
    this.loadBackground();
    //加载性别
    this.loadSex();
    //加载级别
    this.loadUserRank();
    //加载排班
    this.loadScheduling();
  },
  methods: {

    // 打开添加的弹出层
    handleAdd() {
      this.addopen = true
      this.reset()
      this.title = '---添加用户---'
    },
    //添加
    addhandleSubmit() {
      this.$refs.addform.validate(valid => {
        if (valid) {
          this.$http.post("/system/user/add",this.addform).then(resp=>{
            if(resp.data.code===200){
              this.$message.success("添加成功");
              this.addopen=false;
              this.loadUser();
            }else{
              this.$message.error("添加失败");
            }
          })
        }
     })
    },
    // 打开修改的的弹出层并加载数据
    handleUpdate(row) {
      this.title = '---修改用户信息---'
      const userId = row.userId
      this.updateopen = true
      this.$http.get("/system/user/getUserById/"+userId).then(resp => {
        if (resp.data.code === 200) {
          // this.$message.success("查询成功")
          console.log(resp.data.data)
          this.updateform = resp.data.data
        }
      })
    },
    //修改
    updatehandleSubmit() {
      this.$refs.updateform.validate(valid => {
        if (valid) {
          this.$http.post("/system/user/update",this.updateform).then(resp=>{
            if(resp.data.code===200){
              this.$message.success("修改成功");
              this.updateopen=false;
              this.loadUser();
            }else{
              this.$message.error("修改失败");
            }
          })
        }
      })
    },
    /*执行删除*/
    handleDelete(row) {
      const userIds = row.userId || this.ids
      this.$confirm('此操作将永久删除该用户数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.get("/system/user/delete/"+userIds).then(resp=>{
          this.$message.success("删除成功");
          this.loadUser();
        }).catch(error => {
          this.$message.error("删除失败");
          console.error('删除请求失败:', error);
        });
      }).catch(() => {
        this.$message.warning("取消删除");
      });
    },
    //批量删除事件
    batchDelete(){
      this.userIds=this.selectedRows.map(item=>item.userId)
        this.$confirm("确认删除选中的"+this.userIds.length+"项吗？","提示",{
          confirmButtonText:"确定",
          cancelButtonText:"取消",
          type:"warning"
        }).then(()=>{
          this.$http.get("/system/user/batchDelete?userIds="+this.userIds).then(resp=>{
              this.$message.success("删除成功");
              this.loadUser();
          }).catch(error => {
            this.$message.error("删除失败");
            console.error('删除请求失败:', error);
          });
        }).catch(() => {
          this.$message.warning("取消删除");
        });
    },
    cancelRoleUser() {
      this.selectRoleOpen = false
    },
    // 分页pageSize变化时触发 接收新页面大小值val。更新queryParams.pageSize为新值。触发loadUser方法加载数据
    handleSizeChange(val) {
      this.queryParams.pageSize = val
      this.loadUser()
    },
    // 点击上一页  下一页，跳转到哪一页面时触发
    handleCurrentChange(val) {
      this.queryParams.pageNum = val
      this.loadUser()
    },
    /*分配角色*/
    handleSelectRole(row) {
      this.selectRoleOpen = true
      this.title = '---分配角色---'
      this.currentUserId = row.userId || this.ids[0]
      this.$http.get("/system/role/selectAllRole").then(res => {
        console.log(res.data)
        this.roleTableList = res.data.data
        this.$nextTick(() => {
          // 根据当前用户UserId查找之前拥有的角色IDS
          this.$http.get("/system/role/findRolesByUserId/"+this.currentUserId).then(res2=>{
            const roleIds = res2.data.data
            this.$nextTick(() => {
              let roleIdsArray = [];
              // 检查 roleIds 是否为数组
              this.roleTableList.forEach(r2 => {
                if (roleIds.includes(r2.roleId)) {
                  roleIdsArray.push(r2.roleId);
                  this.$refs.roleListTable.toggleRowSelection(r2, true);
                }
              });
            });
          })
        })
      })
    },
    // 分配角色多选择框选择时触发
    handleRoleTableSelectionChange(selection) {
      this.roleIds = selection.map(item => item.roleId)
      this.roleSingle = selection.length === 0
    },
    selectionChange(selection){
      /*将选中的用户转换为用户ID的数组并赋值给this.userIds。
        判断选择的长度，如果为1，则将this.userSingle设为true，否则设为false。
        判断选择的长度，如果为0，则将this.multiple设为true，否则设为false。*/
      this.userIds = selection.map(item => item.userId)
      this.selectedRows = selection
      this.single = selection.length > 1
      this.multiple = selection.length === 0 || selection.length === null
    },
    // 保存用户和角色之间的关系
    handleSaveRoleUserSubmit() {
      this.$http.post("/system/role/saveRoleUser/"+this.currentUserId+"/"+this.roleIds).then(res => {
        if (res.data.code === 200) {
          this.$message.success("分配角色成功")
          this.selectRoleOpen = false
          this.loadUser()
        } else {
          this.$message.error("分配角色失败")
        }
      })
    },

    //格式化表格
    deptFormatter(row){
      let deptName="未知";
      this.deptOptions.filter(item=>{
        if(row.deptId===item.deptId){
          deptName=item.deptName;
        }
      })
      return deptName;
    },
    // 格式化级别
    userRankFormatter(row){
      let userRankName="未知";
      this.userRankOptions.filter(item=>{
        if(row.userRank===item.dictValue){
          userRankName=item.dictLabel;
        }
      })
      return userRankName;
    },
    // 格式化性别
    sexFormatter(row){
      let sexName="未知";
      this.sexOptions.filter(item=>{
        if(row.sex===item.dictValue){
          sexName=item.dictLabel;
        }
      })
      return sexName;
    },
    // 格式化排班
    schedulingFlagFormatter(row){
      let schedulingName="未知";
      this.schedulingOptions.filter(item=>{
        if(row.schedulingFlag===item.dictValue){
          schedulingName=item.dictLabel;
        }
      })
      return schedulingName;
    },
    // 格式化状态
    statusFormatter(row){
      let statusName="未知";
      this.statusOptions.filter(item=>{
        if(row.status===item.dictValue){
          statusName=item.dictLabel;
        }
      })
      return statusName;
    },
    //格式化学历
    backgroundFormatter(row){
      let backgroudName="未知";
      this.backgroundOptions.filter(item=>{
        // console.log(item.dictValue)
        if(row.background===item.dictValue){
          backgroudName=item.dictLabel;
        }
      })
      return backgroudName;
    },
    //加载表格
    loadUser() {
      this.$http.post("/system/user/listByPage",this.queryParams).then(resp=>{
        this.userTableList= resp.data.data.records;
        this.queryParams.total=resp.data.data.total;
      })
    },
    //加载性别
    loadSex(){
      this.$http.get("/system/dict/data/type/sys_user_sex").then(resp=>{
        this.sexOptions=resp.data.data;
      })
    },
    //加载级别
    loadUserRank(){
      this.$http.get("/system/dict/data/type/sys_user_level").then(resp=>{
        this.userRankOptions=resp.data.data;
      })
    },
    //加载部门: 排错的步骤 1.浏览器控制台
    loadDept() {
      this.$http.get("/system/dept/list").then(resp=>{
        // console.log(resp.data.data)
        this.deptOptions=resp.data.data;
      })
    },
    //加载所有的学历
    loadBackground(){
      this.$http.get("/system/dict/data/type/sys_user_background").then(resp=>{
        this.backgroundOptions=resp.data.data;
      })
    },
    //加载排班
    loadScheduling(){
      this.$http.get("/system/dict/data/type/his_scheduling_status").then(resp=>{
        this.schedulingOptions=resp.data.data;
      })
    },
    //加载状态
    loadStatus() {
      this.$http.get("/system/dict/data/type/sys_normal_disable").then(resp=>{
        this.statusOptions=resp.data.data;
      })
    },
    /*重置按钮*/
    resetQuery() {
      this.queryParams={
        pageNum: 1,
        pageSize: 5,
        userName: undefined,
        phone: undefined,
        status: undefined,
        deptId: undefined,
        userRank: undefined,
        background: undefined,
        schedulingFlag: undefined,
        dateRange: []
      }
      this.loadUser()
    },
    // 重置表单
    reset() {
      this.resetForm('addform')
      this.addform = {
        userId: undefined,
        userName: undefined,
        phone: undefined,
        sex: '0',
        age: 0,
        status: '0',
        email: undefined,
        strong: undefined,
        honor: undefined,
        introduction: undefined,
        remark: undefined,
        schedulingFlag: '0'
      }
    },
    // 取消
    cancel() {
      this.addopen = false
      this.updateopen = false
      this.title = '操作已取消'
    },
    handleQuery(){
      this.loadUser();
    },
    resetForm() {
      this.$refs.addform.resetFields()
      this.$refs.updateform.resetFields()
    },
  }
}
</script>
<style scoped>

</style>